@import '@automattic/typography/styles/variables';
@import '@automattic/components/src/styles/typography';
@import '@wordpress/base-styles/variables';
@import "@wordpress/base-styles/breakpoints";
@import '@wordpress/base-styles/mixins';

$blueberry-color: #3858e9;

.chatbox-message__dislike-thumb {
	display: flex;
	width: 96%;
	justify-content: flex-end;
	margin-top: 4px;

	svg {
		padding: 14px;
		background-color: $blueberry-color;
		border-radius: 2px;
	}
}

.odie-chatbox__action-message {
	display: flex;
	flex-direction: row;
	gap: 8px;
	flex-wrap: wrap;

	.odie-chatbox-dislike-feedback-message {
		flex: 1;

		p {
			width: 80%;
			display: flex;
			padding: 16px;
			align-items: center;
			justify-content: start;
			background-color: var( --studio-gray-0 );
			border-radius: 8px 8px 8px 0;
			font-size: 0.875rem;
			margin-bottom: 0;
		}
		p:nth-of-type( 2 ) {
			margin-top: 8px;
		}
	}

	.odie-chatbox-typing-placeholder {
		margin: 0 16px;

		// The typing placeholder uses ThinkingMessage component from Agenttic UI.
		// We need to hide the svg icon because it's meant for AI, not human responses.
		// We need the `ThinkingMessage` because of its cool shimmering effect.
		[data-slot='thinking'] > div {
			display: none;
		}
	}
}

.odie-chatbox-message {
	display: flex;
	flex-direction: column;
	word-wrap: break-word;
	color: $gray-900;
	font-size: $font-size-large;
	line-height: 1.6;
	width: 100%;
	box-sizing: border-box;
	text-wrap: pretty;
	word-break: break-word;
	max-width: 100%;

	p {
		font-size: 100%;
	}

	&.is-sending {
		opacity: 0.5;
	}

	&.odie-chatbox-message-user {
		border-radius: 24px 24px 8px 24px;
		background-color: $gray-200;
		width: max-content;
		margin-right: 16px;
		padding: 10px 16px;
		max-width: calc( 100% - 32px );
		align-self: flex-end;

		p {
			color: $gray-900;
			padding: 0;
			span {
				background-color: transparent;
			}
		}

		blockquote {
			background-color: transparent;
			border-left: 2px solid var( --color-neutral-0 );
			margin: 8px 0 16px;
			padding: 8px 16px;
		}
	}

	ol,
	ul {
		margin: 0;
		padding-left: 20px;
		padding-right: 20px;
		font-style: normal;

		li {
			margin-bottom: 6px;

			p {
				padding: 0;
			}
		}
	}

	ul {
		list-style: initial;
	}

	img {
		max-width: 100%;
		height: auto;
	}

	.odie-chatbox-message__content {
		p {
			margin-bottom: 0;
			margin-top: 0;
		}

		h1 {
			@include heading-2x-large();
		}
		h2 {
			@include heading-x-large();
		}
		h3 {
			@include heading-large();
		}
		h4 {
			@include heading-medium();
		}
		h5 {
			@include heading-small();
		}
		h6 {
			@include heading-small();
		}

		u {
			text-decoration: underline;
		}

		pre {
			padding: 0.5em;
			white-space: pre-wrap;
			word-break: break-word;
			background-color: var( --studio-white );
		}

		span {
			font-size: $font-size-large;

			a {
				color: inherit;

				&:hover {
					text-decoration: none;
				}
			}
		}
	}

	&.odie-chatbox-message-bot {
		.odie-chatbox-message__content {
			flex: 1;
			max-width: calc( 100% - 32px );

			> *:not( :first-child ) {
				padding-top: 8px;
			}

			> *:not( :last-child ) {
				padding-bottom: 8px;
			}

			ol,
			ul {
				padding-left: 20px;
				padding-right: 20px;
			}
		}

		button[aria-pressed='true'] {
			background-color: var( --studio-gray-5 );
			opacity: 1;
			svg {
				color: var( --color-foreground );
			}
		}
	}

	&.odie-chatbox-message-error {
		flex-direction: column;
	}

	.MessageActions-module_container {
		width: 30%;
		z-index: 1;
	}

	.chat-feedback-wrapper {
		margin-top: -24px;
		width: 100%;

		.odie-sources-foldable-card {
			box-shadow: none;
			margin-bottom: 0;
			padding: 0;

			&:not( .is-expanded ) {
				.foldable-card__content {
					border: none;
				}
			}

			&.is-expanded {
				.foldable-card__content {
					max-height: 100vh;
				}
			}

			.foldable-card__header {
				margin-left: auto;
				width: 70%;
				min-height: 24px;
				padding: 0;
			}

			.foldable-card__summary,
			.foldable-card__summary-expanded {
				color: var(--studio-gray-80);
				margin-right: 24px;
			}

			.foldable-card__main {
				button {
					height: 24px;
					width: 24px;
				}
			}

			.foldable-card__secondary {
				@media (max-width: #{ ($break-mobile) }) {
					flex: 1 1;
				}
			}

			.foldable-card__content {
				margin-top: 12px;
				border: none;

				.odie-chatbox-message-sources {
					border: 1px solid var( --color-neutral-5 );
					border-radius: 8px;
				}

				.odie-support-doc-link__link {
					a {
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding: 4px 8px;
						gap: 8px;
					}
				}
			}
		}

		.disclaimer {
			color: var( --studio-gray-60 );
			font-size: $font-body-extra-small;
			text-align: start;
			margin-top: 8px;

			.components-external-link {
				color: var( --studio-gray-20 );
			}
		}
	}

	.chat-feedback-wrapper-third-party-cookies {
		margin-left: 0;
		width: 80%;
	}

	.odie-feedback-component-container {
		&.odie-question-collapse {
			margin-top: 0;
		}
		margin-top: 32px;
		font-size: 1rem;
	}

	&.odie-chatbox-message.odie-chatbox-message-business.odie-chatbox-message-conversation-feedback {
		flex-wrap: wrap;
		gap: 8px;
		flex-direction: row;
		padding: 0 16px;

		.message-feedback-submit {
			margin-left: 46px;
			align-items: start;

			a {
				gap: 4px;
			}
		}

		.odie-chatbox-message__content {
			flex-basis: 100%;
		}

		.odie-conversation__feedback {
			width: 100%;
			display: flex;
			align-items: center;

			&.has_message {
				display: none;
			}

			p {
				background-color: unset !important;
				font-weight: 600;
			}

			.odie-conversation-feedback__thumbs {
				display: flex;
				gap: var(--spacing-1, .25rem);

				.odie-conversation-feedback__thumbs-button:hover svg {
					color: var(--color-foreground, oklch(.241 0 0));
				}

				&-button {
					padding: 0;
					color: $gray-700;
				}
			}
		}

		.odie-rating-feedback-message {
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: flex-end;
			padding: 8px 0;

			> div {
				border-radius: 24px 24px 8px 24px;
				background-color: $gray-200;
				width: max-content;
				margin-right: 16px;
				padding: 10px 16px;
				max-width: calc( 100% - 32px );
				align-self: flex-end;
			}
		}

		.odie-conversation-feedback__message {
			h3 {
				font-weight: 500;
				line-height: 24px;
			}

			p {
				padding: 12px 0;
				background-color: unset !important;
				color: var( --studio-gray-80 );
				line-height: 20px;
			}

			.odie-conversation-feedback__reason {
				padding-bottom: 12px;
			}

			button.is-primary {
				margin-top: 10px;
				margin-right: 8px;
				background: var( --studio-wordpress-blue, #3858e9 );
			}

			button.is-tertiary {
				color: var( --studio-wordpress-blue, #3858e9 );
			}
		}
	}

	.odie-conversation__feedback-loading {
		width: 100%;
		text-align: center;
		margin: 12px;
	}
}

.odie-chatbox-message p:first-of-type {
	padding-top: 0;
}

.odie-chatbox-message p:last-of-type {
	margin-bottom: 0;
	padding-bottom: 0;
}

.odie-chatbox-message.odie-chatbox-message-bot.odie-chatbox-message-message {
	flex-wrap: wrap;
	flex-direction: column;
}

.odie-fullscreen {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 999999;
	display: flex;
	justify-content: center;
	align-items: center;
	background-color: rgba( 0, 0, 0, 0.1 );

	.odie-fullscreen-backdrop {
		width: 75vw;
		height: 85vh;
		overflow: scroll;

		.odie-chatbox-message {
			box-shadow: 0 0 0 1px var( --color-border-subtle );
			width: auto;
			height: auto;
			margin: auto;
			font-size: $font-body;
			padding-top: 0;
		}
	}
}

.odie-sources {
	display: flex;
	align-items: center;
	gap: 4px;
	align-self: stretch;
	border-radius: 4px;
	background-color: var( --studio-gray-0 );
	width: fit-content;
	padding: 0;
	margin: 4px 0;

	.odie-sources-link {
		overflow-wrap: anywhere;
		font-style: normal;
		padding: 4px 16px;
		color: inherit;

		&:hover {
			text-decoration: none;
		}
	}

	svg.gridicons-external {
		min-width: 18px;
	}
}

.odie-sources-inline {
	display: inline;
	padding: 0;
	margin: 0;

	.odie-sources-link {
		padding: 0;
	}
}

$feedback-button-size: 28px;

.odie-feedback-component-container {
	display: flex;
	justify-content: space-between;
	align-items: center;

	.odie-feedback-component-button-container {
		display: flex;
		align-items: center;
		gap: 8px;

		.odie-feedback-component-button {
			border: solid 0.5px var( --studio-gray-5 );
			padding: 6px;

			&:focus {
				outline: 0;
			}
		}

		.odie-feedback-component-button-liked-pressed,
		.odie-feedback-component-button-disliked-pressed {
			background-color: $blueberry-color;
			cursor: default;
			pointer-events: none;
		}

		.odie-feedback-component-button-disliked-disabled,
		.odie-feedback-component-button-liked-disabled {
			background-color: var( --color-surface );
			pointer-events: none;
		}
	}
}

$custom-border-corner-size: 16px;

.odie-gradient-to-white {
	background: linear-gradient( 180deg, rgba( 255, 255, 255, 0 ) 0%, #fff 50% );
	display: flex;
	align-items: center;
	gap: 8px;
	height: 100px;
	justify-content: center;
	z-index: 5;
	pointer-events: none;
	position: fixed;
	width: 100%;

	&.is-hidden {
		opacity: 0;
		bottom: 0 !important;
		transition:
			opacity 0.3s ease 0.3s,
			bottom 0.3s ease 0.3s;

		.odie-jump-to-recent-message-button {
			pointer-events: none;
		}
	}

	&.is-visible {
		opacity: 1;
		bottom: 24px;
		transition:
			opacity 0.3s ease 1.2s,
			bottom 0.3s ease 1.2s;
	}

	.odie-jump-to-recent-message-button {
		pointer-events: auto;
		position: relative;
		bottom: 24px;
		font-family: $a8c-font-family-sans;
		cursor: pointer;
		margin: 0;
		outline: 0;
		overflow: hidden;
		text-align: center;
		text-overflow: ellipsis;
		text-decoration: none;
		vertical-align: top;
		box-sizing: border-box;
		font-size: $font-body;
		line-height: 1;
		appearance: none;
		background-color: $blueberry-color;
		color: var( --studio-white );
		border: 1px none;
		display: flex;
		height: 28px;
		padding: 12px 16px;
		padding-right: 8px;
		justify-content: center;
		align-items: center;
		border-radius: $custom-border-corner-size;

		&:hover {
			color: var( --studio-white );
			border-color: inherit;
		}

		&.is-active {
			border-width: 1px;
		}
	}
}

.odie-chatbox-message-avatar-wapuu-liked {
	-webkit-animation: wapuu-joy-animation 1300ms both;
	animation: wapuu-joy-animation 1300ms both;
}

@keyframes wapuu-joy-animation {
	0% {
		-webkit-transform: scale3d( 1, 1, 1 );
		transform: scale3d( 1, 1, 1 );
	}

	30% {
		-webkit-transform: scale3d( 1.25, 0.75, 1 );
		transform: scale3d( 1.25, 0.75, 1 );
	}

	40% {
		-webkit-transform: scale3d( 0.75, 1.25, 1 );
		transform: scale3d( 0.75, 1.25, 1 );
	}

	50% {
		-webkit-transform: scale3d( 1.15, 0.85, 1 );
		transform: scale3d( 1.15, 0.85, 1 );
	}

	65% {
		-webkit-transform: scale3d( 0.95, 1.05, 1 );
		transform: scale3d( 0.95, 1.05, 1 );
	}

	75% {
		-webkit-transform: scale3d( 1.05, 0.95, 1 );
		transform: scale3d( 1.05, 0.95, 1 );
	}

	100% {
		-webkit-transform: scale3d( 1, 1, 1 );
		transform: scale3d( 1, 1, 1 );
	}
}

.odie-feedback-message {
	font-weight: 500;
	font-size: 1rem;
	width: 100%;
	height: 100%;
	min-height: 45px;
	display: flex;
	align-items: center;
	color: var( --studio-gray-100 );

	.odie-feedback-component-thanks,
	.odie-feedback-component-question {
		display: flex;
		align-items: center;
		transition: opacity 0.3s ease;
		height: 100%;
	}

	.odie-question-out {
		animation: question-out-animation 0.3s ease both;
	}

	.odie-question-hidden {
		opacity: 0;
	}

	.odie-thanks-in {
		animation: thanks-in-animation 0.3s ease-out both;
	}

	.odie-thanks-hidden {
		opacity: 0;
	}
}

.odie-question-collapse {
	animation: odie-question-collapse-animation 0.3s ease-in-out 2.5s forwards;
	overflow: hidden;
}

@keyframes odie-question-collapse-animation {
	0% {
		height: $feedback-button-size;
	}

	100% {
		height: 0;
	}
}

@keyframes question-out-animation {
	0% {
		opacity: 1;
	}

	100% {
		opacity: 0;
	}
}

@keyframes thanks-in-animation {
	0% {
		transform: translateY( 1rem );
		opacity: 0;
	}

	100% {
		transform: translateY( 0 );
		opacity: 1;
	}
}

.odie-chatbox-message-sources-container {
	.foldable-card {
		margin: 0 !important;
		width: 100% !important;

		.foldable-card__header > span.foldable-card__main > button > span {
			display: none;
		}
	}

	.odie-chatbox-message-sources {
		margin: 12px;
	}

	&:nth-last-child( 2 ) {
		.foldable-card {
			box-shadow: 0 -1px 0 rgba( 0, 0, 0, 0.1 );
		}
	}
}

.odie-chatbox-invalid__message {
	color: rgb( 140, 35, 44 );
	font-size: 0.75rem;
	top: 66%;
	width: 95%;
	background: #fff;
	position: fixed;
	bottom: 73px;
	height: 30px;
	text-align: center;
	padding-top: 6px;
}

.chatbox-messages__content {
	/* normal scrollable content */
	overflow-y: auto;
}

.chatbox-loading-chat__spinner {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	border-radius: 24px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var( --studio-white );
	z-index: 10;
	opacity: 0;
	pointer-events: none;
	transition: opacity 500ms ease-in-out;
}

.chatbox-loading-chat__spinner.is-visible {
	opacity: 1;
	pointer-events: all;
}
